/*
 * 作者:熊猫
 * 日期:2017 - 3 - 14 7 - 45 - 14
 *
 */

package net.lainiao.morethread.Chapter6.demo1;

import java.util.concurrent.ConcurrentLinkedDeque;

/**
 *实现并发列表中的非阻塞列表
 */
public class Main {
    public static void main(String[] args) {
        ConcurrentLinkedDeque<String> list=new ConcurrentLinkedDeque<>();
        Thread[] threads=new Thread[100];
        for (int i = 0; i < 100; i++) {
            AddTask addTask=new AddTask(list);
            Thread thread=new Thread(addTask);
            threads[i]=thread;
            thread.start();
        }
        for (int i = 0; i < 100; i++) {
            try {
                threads[i].join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("AddTask Size :"+list.size());

        for (int i = 0; i < 100; i++) {
            PollTask pollTask=new PollTask(list);
            threads[i]=new Thread(pollTask);
            threads[i].start();
        }

        for (int i = 0; i < 100; i++) {
            try {
                threads[i].join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

        System.out.println("PollTask Size:"+list.size());
    }
}
